package com.cn.onetrip.adapter;

import java.util.Vector;

import android.content.Context;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.cn.onetrip.activity.R;
import com.cn.onetrip.objects.InfosListObj;

public class InfoMessageItemAdapter extends BaseAdapter {

	public Vector<InfosListObj> mModels = new Vector<InfosListObj>();
	private LayoutInflater mInflater;
	private Context mContext;
	private ListView mListView;
	private Handler mhandler;

	public InfoMessageItemAdapter(Context context, ListView listView,
			Handler handler) {
		mInflater = LayoutInflater.from(context);
		mContext = context;
		mListView = listView;
		mhandler = handler;
	}

	public void addInfoNews(String title, String time, String source) {
		InfosListObj model = new InfosListObj();
		model.title = title;
		model.time = time;
		model.source = source;
		mModels.add(model);
	}

	public void clean() {
		mModels.clear();
	}

	@Override
	public int getCount() {
		return mModels.size();
	}

	@Override
	public Object getItem(int position) {
		if (position >= getCount()) {
			return null;
		}
		return mModels.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		InfosListObj model = mModels.get(position);
		convertView = mInflater.inflate(R.layout.info_message_items, null);
		convertView.setTag(position);
		TextView content = (TextView) convertView
				.findViewById(R.id.InfoItemMessageText);
		TextView time = (TextView) convertView
				.findViewById(R.id.InfoItemMessageTime);
		content.setText(model.title);
		time.setText(model.source + "    " + model.time);
		return convertView;
	}

}
